//
//  HMVisitorTableViewController.swift
//  Weibo
//
//  Created by mac on 2017/6/7.
//  Copyright © 2017年 mac. All rights reserved.
//

import UIKit

class HMVisitorTableViewController: UITableViewController {
    //是否登录的标记
    var isLogin:Bool = false
    //访客视图
    var visitorView:HMVisitorView?
    override func loadView() {
        super.viewDidLoad()

        if isLogin{
            //登录成功
            super.loadView()
            
        }else{
            //没有登录
            setupNavUI()
            //创建访客视图
            visitorView=HMVisitorView()
            //设置代理对象
            visitorView?.delegate=self
            //设置登录执行闭包
            visitorView?.loginCallBack={[unowned self]in
                self.enterOAuthVC()
            }
            view=visitorView
        }
      
    }
    
    override func viewDidLoad(){
        super.viewDidLoad()
    }
    //设置导航栏按钮
    private func setupNavUI(){
        //自定义视图的UIBarbuttonItem构造方法
        navigationItem.leftBarButtonItem=UIBarButtonItem(title: "注册", target: self, action: #selector(registerButtonAction))
        navigationItem.rightBarButtonItem=UIBarButtonItem(title: "登录", target: self, action: #selector(loginButtonAction))
    }
    //导航栏按钮点击事件
    @objc private func registerButtonAction(){
    
        enterOAuthVC()
    }
    @objc private func loginButtonAction(){
        enterOAuthVC()
    }
    //登录界面
    private func enterOAuthVC(){
        let oauthVC = HMOAuthViewController()
        let nav = HMNavigationViewController(rootViewController: oauthVC)
        self.present(nav,animated: true,completion: nil)
  
    }

}
extension HMVisitorTableViewController:HMVisitorViewDelegate{
    func loginOperation() {
        print("xxx")
    }
}
